/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BaoCaoTongKetInternalFrame.java
 *
 * Created on Jul 28, 2010, 6:15:05 AM
 */

package GUI;

import BUS.DiemHocTapBUS;
import BUS.HocSinhBUS;
import BUS.LopBUS;
import BUS.MonHocBUS;
import BUS.NamHocBUS;
import POJO.HocSinhPOJO;
import POJO.LopPOJO;
import POJO.MonHocPOJO;
import POJO.NamHocPOJO;
import java.util.ArrayList;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author DarkMagikian
 */
public class BaoCaoTongKetInternalFrame extends javax.swing.JInternalFrame {

    private ArrayList<String> DSMaNamHoc = new ArrayList<String>();
    private ArrayList<String> DSMaMonHoc = new ArrayList<String>();

    public void loadjCBNamHoc(){
        try{
            ArrayList<NamHocPOJO> NHlist = NamHocBUS.selectAll();
            DefaultComboBoxModel dcb = new DefaultComboBoxModel();
            int size = NHlist.size();
            for(int i=0;i<size;i++){
                this.DSMaNamHoc.add(NHlist.get(i).getMaNamHoc());
                dcb.addElement(NHlist.get(i).getNamHoc());
            }
            this.jCBNamHoc.setModel(dcb);
        }catch(Exception ex){
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }

    public void loadjCBMon() {
        DefaultComboBoxModel dcm = new DefaultComboBoxModel();
        ArrayList<MonHocPOJO> MHList = MonHocBUS.selectAll();
        for (int i = 0; i < MHList.size(); i++) {
            this.DSMaMonHoc.add(MHList.get(i).getMaMonHoc());
            dcm.addElement(MHList.get(i).getTenMonHoc());
        }
        this.jCBMonHoc.setModel(dcm);
    }

    public void showList(){
        try{
            ArrayList<LopPOJO> list = LopBUS.selectLop_Nam(this.jCBNamHoc.getSelectedItem().toString());
            DefaultTableModel dtm = new DefaultTableModel(){
                @Override
                public boolean isCellEditable(int row,int column){
                return false;
                }
            };
            dtm.addColumn("STT");
            dtm.addColumn("Lớp");
            dtm.addColumn("Sỉ số");
            dtm.addColumn("Số lượng đạt");
            dtm.addColumn("Tỷ lệ");
            int size = list.size();
            dtm.setRowCount(size);
            for(int i=0;i<size;i++){
                dtm.setValueAt(i+1, i, 0);
                dtm.setValueAt(list.get(i).getMaLop(), i, 1);
                ArrayList<HocSinhPOJO> HSList = HocSinhBUS.selectHocSinh_Lop(list.get(i).getMaLop());
                dtm.setValueAt(HSList.size(), i, 2);
                String MaNamHoc = this.DSMaNamHoc.get(this.jCBNamHoc.getSelectedIndex());
                String MaMonHoc = this.DSMaMonHoc.get(this.jCBMonHoc.getSelectedIndex());
                String HocKy = this.jCBHocKy.getSelectedItem().toString();
                int SoHSDat = DiemHocTapBUS.soHocSinhDat(MaNamHoc, list.get(i).getMaLop(), HocKy , MaMonHoc);
                dtm.setValueAt(SoHSDat, i, 3);
                if(HSList.size()>0){
                    float TyLe = SoHSDat*100/HSList.size();
                    dtm.setValueAt(String.valueOf(TyLe)+"%", i, 4);
                }else{
                    dtm.setValueAt("100%", i, 4);
                }
            }
            this.jTDanhSach.setModel(dtm);
            this.jLTongSoLop.setText(String.valueOf(this.jTDanhSach.getRowCount()));
        }catch(Exception ex){
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }

    /** Creates new form BaoCaoTongKetInternalFrame */
    public BaoCaoTongKetInternalFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jCBNamHoc = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jCBMonHoc = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jCBHocKy = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLTongSoLop = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTDanhSach = new javax.swing.JTable();
        jBThoat = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();

        setClosable(true);
        setIconifiable(true);
        setTitle("Quản lý học sinh - Báo cáo tổng kết môn");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 24));
        jLabel1.setForeground(new java.awt.Color(0, 102, 255));
        jLabel1.setText("Báo cáo tổng kết môn");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Thông tin", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 51, 255))); // NOI18N

        jLabel2.setText("Năm học:");

        jCBNamHoc.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jCBNamHocItemStateChanged(evt);
            }
        });

        jLabel3.setText("Môn học:");

        jCBMonHoc.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jCBMonHocItemStateChanged(evt);
            }
        });

        jLabel4.setText("Học kỳ:");

        jCBHocKy.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2" }));
        jCBHocKy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCBHocKyActionPerformed(evt);
            }
        });

        jLabel5.setText("Tổng số:");

        jLTongSoLop.setText("0");

        jLabel7.setText("lớp");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(68, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jCBNamHoc, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jCBMonHoc, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(jLTongSoLop)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7))
                    .addComponent(jCBHocKy, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(62, 62, 62))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jCBNamHoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jCBHocKy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jCBMonHoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jLTongSoLop)
                    .addComponent(jLabel7))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Danh sách", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 51, 255))); // NOI18N

        jTDanhSach.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jTDanhSach);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE)
                .addContainerGap())
        );

        jBThoat.setText("Thoát");

        jLabel6.setFont(new java.awt.Font("Arial", 0, 11));
        jLabel6.setText("Copyright ©2010 - Group 12™");
        jLabel6.setEnabled(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(130, 130, 130)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 465, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 187, Short.MAX_VALUE)
                .addComponent(jBThoat, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBThoat, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        // TODO add your handling code here:
        this.loadjCBNamHoc();
        this.loadjCBMon();
        this.showList();
    }//GEN-LAST:event_formInternalFrameOpened

    private void jCBNamHocItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCBNamHocItemStateChanged
        // TODO add your handling code here:
        this.showList();
    }//GEN-LAST:event_jCBNamHocItemStateChanged

    private void jCBMonHocItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCBMonHocItemStateChanged
        // TODO add your handling code here:
        this.showList();
    }//GEN-LAST:event_jCBMonHocItemStateChanged

    private void jCBHocKyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCBHocKyActionPerformed
        // TODO add your handling code here:
        this.showList();
    }//GEN-LAST:event_jCBHocKyActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBThoat;
    private javax.swing.JComboBox jCBHocKy;
    private javax.swing.JComboBox jCBMonHoc;
    private javax.swing.JComboBox jCBNamHoc;
    private javax.swing.JLabel jLTongSoLop;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTable jTDanhSach;
    // End of variables declaration//GEN-END:variables

}
